#pragma once

#include "MaterialManager.h"
#include <list>

enum ModelType
{
	MT_IFC,
	MT_GML,
};

enum ObjectType {
	OT_PROJECT,
	OT_SITE,
	OT_BUILDING,
	OT_STOREY,
	OT_SPACE,

//	OT_ANNOTATION,
	OT_BEAM,
	OT_BUILDINGELEMENTCOMPONENT,
	OT_BUILDINGELEMENTPROXY,
	OT_COLUMN, 

	OT_COVERING,
	OT_CURTAINWALL,
	OT_DOOR,
	OT_ELEMENTASSEMBLY,
	OT_FASTENER,
	OT_FOOTING,
	OT_MECHANICALFASTENER,
	OT_MEMBER,
	OT_PILE,
	OT_PLATE,
	OT_RAILING,
	OT_RAMP,
	OT_RAMPFLIGHT,
	OT_ROOF,
	OT_SLAB,
	OT_STAIR,
	OT_STAIRFLIGHT,
	OT_STRUCTURALCURVEMEMBER,
	OT_WALL,
	OT_WINDOW,
	OT_AIRTERMINAL,
	OT_DISTRIBUTIONELEMENT,
	OT_FURNISHINGELEMENT,
	OT_FLOWTERMINAL,
	OT_FLOWFITTING,
	OT_FLOWSEGMENT,
	OT_FLOWCONTROLLER,
	OT_GRID,
	UNKNOWN,
};

struct CUSTOMVERTEX {
	float	x;
	float	y;
	float	z;
    float   nx;
    float   ny;
    float   nz;
};

struct VECTOR3f {
	float	x;
	float	y;
	float	z;
};

struct VECTOR2f {
	float	x;
	float	y;
};

class SPolygon
{
public:
	int			startVertex;
	int			startIndex;
	int			primitiveCount;
	SMaterial	*mtrl;
	SPolygon	*next;
	SPolygon()  :next(NULL) {}
};

class S3DObject 
{
public:
	int			ref;
    ObjectType	type;
	char		*name;
	S3DObject	*next;
	bool		visible;
	SPolygon	*polygon;
	S3DObject() :polygon(NULL) {}
};


class CModel //abstract
{
//attributes
public:
	int         m_ref;  
	char*		m_URI;
    char*		m_filePath;
    char*		m_fileName;
	ModelType	m_type;
	S3DObject   *m_p3DObject; 
	
    VECTOR3f	m_minBB;
    VECTOR3f	m_maxBB;

	int			 m_nrIndices;
	int			 m_nrVertices;
	int			 *m_pIndices;
	CUSTOMVERTEX *m_pVertices;


// create functions
protected:
	CModel(void) {}; 
public:
	~CModel(void) {};

// overrideable functions
public:
	virtual void OpenModel() {};   // pure virtual
	virtual void CloseModel() {};  // pure virtual 

protected:
	virtual void Add3DObjects() {};
	virtual void Del3DObjects(S3DObject *object) {};
	virtual void DelPolygons(SPolygon *polygon) {};
};


class CIfcModel : public CModel
{
//attributes
public:
	char*		  m_schemaFile;
	double		  m_unitScale;

// create functions
public:
	CIfcModel(void);
	~CIfcModel(void);

// reading/parsing functions
private:
	void GetUnitScale();
	void GetBoundingBox();

	void Add3DObjects();
	void Add3DObjectsByType(char * ObjectSPFFName, ObjectType type, float R, float G, float B, float alpha);
	void Del3DObjects(S3DObject *object);

	ObjectType GetObjectType(int *instance);

// overrideable functions
public:
	virtual void OpenModel();
	virtual void CloseModel();
};


class CGmlModel : public CModel
{
public:
	VECTOR2f  *m_pTexMap;

public:
	CGmlModel(void);
	~CGmlModel(void);

// reading/parsing functions
private:
	void GetBoundingBox();
	void Add3DObjects();

// overrideable functions
public:
	virtual void OpenModel();
	virtual void CloseModel();
};



